package com.wz.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.wz.bean.SendedMsg;

public class SmsDbOpenHelper extends SQLiteOpenHelper{

	private static final String DB_NAME = "phone.db";
	private static final int DB_VERSION = 1;
	
	private SmsDbOpenHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}
	
	private static volatile SmsDbOpenHelper mhelper;
	
	//传入的context有可能是一个Activity
    //所以在构造方法中用context.getApplicationContext()尽量得到Application的context
    //避免造成内存泄露的问题
	public static SmsDbOpenHelper getInstance(Context context){
		if(mhelper == null){
			synchronized (SmsDbOpenHelper.class) {
				if(mhelper == null){
					mhelper = new SmsDbOpenHelper(context.getApplicationContext());
				}
			}
		}
		return mhelper;
	}
	

	@Override
	public void onCreate(SQLiteDatabase db) {
		 String sql="create table "+ SendedMsg.TABLE_NAME+" ( "+
	                "_id integer primary key autoincrement, "+
	                SendedMsg.COLUMN_DATE+" integer, "+
	                SendedMsg.COLUMN_FESTIVAL_NAME+" text,"+
	                SendedMsg.COLUMN_CONTENT+" text,"+
	                SendedMsg.COLUMN_NAMES+" text,"+
	                SendedMsg.COLUMN_NUMBERS+" text )";
		db.execSQL(sql );
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
	}

}
